package com.xw.unification.enums;

import lombok.Getter;

import java.util.function.Function;

public enum DigestType {
    MD5     ("MD5"),
    SHA     ("SHA"),
    SHA_1   ("SHA", "HmacSHA1"),
    SHA_224 ("SHA-224"),
    SHA_256 ("SHA-256", "HmacSHA256"),
    SHA_512 ("SHA-512"),
    ;

    @Getter
    private String algorithmName;
    @Getter
    private String macAlgName;
    private Function<String, String> digester;

    DigestType(String algorithmName) {
        this(algorithmName, null, null);
    }

    DigestType(String algorithmName, String macAlgName) {
        this(algorithmName, macAlgName, null);
    }

    DigestType(String algorithmName, String macAlgName, Function<String, String> digester) {
        this.algorithmName = algorithmName;
        this.macAlgName = macAlgName;
        this.digester = digester;
    }

    public String apply(String content) {
        if (content == null || digester == null) {
            return content;
        }
        return digester.apply(content);
    }

}
